package com.siyoumi.entity;

import com.siyoumi.component.XSpringContext;
import com.siyoumi.component.http.XHttpContext;
import com.siyoumi.mybatispuls.JoinWrapperPlus;
import com.siyoumi.mybatispuls.ServiceImplBase;
import com.siyoumi.service.vo.CommonItemData;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


//t_sys_item
@Service
public class SysItemService
        extends ServiceImplBase<SysItemMapper, SysItem> {
    static public SysItemService getBean() {
        return XSpringContext.getBean(SysItemService.class);
    }

    public List<SysItem> listByAppId(String appId) {
        JoinWrapperPlus<SysItem> query = join();
        query.eq("item_app_id", appId)
                .eq("item_x_id", "");
        return list(query);
    }

    public SysItem getEntityByIdSrc(String idSrc, String x) {
        JoinWrapperPlus<SysItem> query = join();
        query.eq("item_x_id", x)
                .eq("item_id_src", idSrc);
        return first(query);
    }

    public SysItem getEntityByIdSrc(String idSrc) {
        return getEntityByIdSrc(idSrc, XHttpContext.getX());
    }

    public List<CommonItemData> getItemDataByIdSrc(String idSrc) {
        SysItem entityItem = getEntityByIdSrc(idSrc);
        if (entityItem == null) {
            return new ArrayList<>();
        }

        return entityItem.commonData();
    }
}
